﻿using Prism.Commands;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WpfApp_PrismRegionBase.ViewModels.Pages;

public class ViewCViewModel : INavigationAware
{
    public string Title { get; set; } = "View C";

    public DelegateCommand<string>? NavForwardDeleateCommand { get; set; }

    private IRegionNavigationJournal? regionNavigationJournal;

    public ViewCViewModel(IRegionManager regionManager)
    {
        NavForwardDeleateCommand = new DelegateCommand<string>(_arg =>
        {
            if (regionNavigationJournal == null)
                return;
            if (_arg == "Forward")
            {
                if (regionNavigationJournal.CanGoForward)
                    regionNavigationJournal.GoForward();
            }
            else
            {
                if (regionNavigationJournal.CanGoBack)
                    regionNavigationJournal.GoBack();
                else
                    regionManager.RequestNavigate("viewRegion", "ViewB");
            }
        });
    }

    public bool IsNavigationTarget(NavigationContext navigationContext)
    {
        return true;
    }

    public void OnNavigatedFrom(NavigationContext navigationContext)
    {
        
    }

    public void OnNavigatedTo(NavigationContext navigationContext)
    {
        regionNavigationJournal = navigationContext.NavigationService.Journal;
    }
}
